package com.power.project.controller;


import com.power.common.domain.PageDataResponse;
import com.power.common.domain.ResponseDTO;
import com.power.project.api.IWw_tagFeign;
import com.power.project.model.bo.TagSaveBO;
import com.power.project.model.bo.TagUserSetBO;
import com.power.project.model.pageInfo.Ww_tagPageInfo;
import com.power.project.model.vo.TagVO;
import com.power.project.service.Ww_tagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


/**
 * 标签控制器
 */

//@Slf4j
//@PowerLog
@RestController
@Api(value = "标签管理", tags = {"标签管理"})
public class Ww_tagController implements IWw_tagFeign {

    @Resource
    private Ww_tagService ww_tagService;


    @Override
    @ApiOperation("查询标签分页列表")
    public ResponseDTO<PageDataResponse<TagVO>> list(Ww_tagPageInfo pageInfo) {
        Assert.notNull(pageInfo, "pageInfo参数不能为空");
        Assert.notNull(pageInfo.getF_tenantid(), "f_tenantid不能为空");
        Page<TagVO> page = ww_tagService.findAll(pageInfo);
        PageDataResponse<TagVO> p = new PageDataResponse<>(page.getContent(), page.getTotalElements(), page.getSize(), pageInfo.getPageNumber() <= 1 ? 1 : pageInfo.getPageNumber());
        return ResponseDTO.succData(p);
    }

    @Override
    public ResponseDTO<List<TagVO>> findAllTags(String tenantId) {
        return ResponseDTO.succData(ww_tagService.findAllTags(tenantId));
    }

    @Override
    public ResponseDTO<List<String>> userIds(String tagId) {
        return ResponseDTO.succData(ww_tagService.getUserIds(tagId));
    }

    @Override
    @ApiOperation("删除标签")
    public ResponseDTO<Void> delete(String tagId) {
        Assert.notNull(tagId, "tagId不能为空");
        ww_tagService.removeById(tagId);
        return ResponseDTO.succ();
    }

    @Override
    @ApiOperation("保存或修改标签")
    public ResponseDTO<Void> save(TagSaveBO saveBO) {
        Assert.notNull(saveBO, "ww_tag不能为空");
        ww_tagService.saveOrUpdate(saveBO);
        return ResponseDTO.succ();
    }

    @Override
    public ResponseDTO<Void> batchSet(TagUserSetBO setBO) {
        ww_tagService.batchSet(setBO);
        return ResponseDTO.succ();
    }

}
